from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QMainWindow, QMessageBox
from Gui.test_UI import Ui_MainWindow
from network.tcp_client import TcpClient
from Agreement_content import send_struct
from PySide2.QtCore import Signal, QObject
from threading import Thread


class MySignal(QObject):
    UpButton = Signal(int)


class TestUi(Ui_MainWindow, QMainWindow):
    def __init__(self, socket):
        super(TestUi, self).__init__()  # 初始化UI类
        self.setupUi(self)

        self.socket = socket  # 获取socket对象

        self.monitor_event()  # 点击事件的函数集

    # 监听点击事件，触发对应槽函数
    def monitor_event(self):
        self.ConnectButton.clicked.connect(self.connect_socket_button_event)
        self.send_network_data_Button.clicked.connect(self.send_data)

    def send_data(self):
        print("触发了send_data点击事件")
        self.socket.get_data("aa3301010009010001000108")

    def connect_socket(self, ip_, port_):
        t = Thread(target=self.socket.create_connect, args=(str(ip_), int(port_)))
        t.start()

    def connect_socket_button_event(self):  # 触发连接事件

        conn_state = self.socket.create_connect(str(ip_), int(port_))


if __name__ == '__main__':
    pass
    # app = QApplication(sys.argv)  # pyqt都需要这个对象，sys.argv是为了确保可以双击运行
    # window = TestUi()
    # window.show()  # 进入QT主循环
    # sys.exit(app.exec_())
